
class Validate{
    constructor(){
		this.emailRegx = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
	}

	//是否是英文单词
    isEnglishWord( keyword ){
    	let word = this.exchangeToLowercase( keyword );
    	let reg = /^[a-zA-Z]+$/g
    	if( reg.test( word ) ) return true;

    	return false;
    }
	
	//是字符串类型
    isString( val ){
    	console.log(Object.prototype.toString.call( val ));
    	return Object.prototype.toString.call( val ) == "[object String]";
    }

	//转小写字母
    exchangeToLowercase( str ){
    	//类型判断是否是字符串
    	if( this.isString(str) ){
    		//是字符串
    		//转为小写字母
    		return str.toLowerCase();
    	}

    	throw new Error("parameter value is not a String type data.");
	}
	
	//检查邮箱是否存在空白字符
	checkEmailWithEmptyFlag( val ){
		
		return this.existEmptyFlag(val);
	}

	//检查邮箱格式
	checkEmail( val ){
		
        return  this.emailRegx.test( val );
	}

	//检查密码是否含有空白字符
	checkpasswordWithEmptyFlag(val){
		return this.existEmptyFlag(val);
	}

	//检查密码是否为空
	checkPasswordEmpty( val ){
		if(  val == "" ) return false;
		return true;
	}

	//检查是否含有字符空串
	existEmptyFlag( val ){
		//检查字符传是否含有空白字符
		let includeEmpty = new RegExp("\\s");
		return includeEmpty.test(val)
	}
	

}
//单例模式需要 -----待解决

module.exports = Validate;